<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/index.css" />
		<!--<link rel="stylesheet" type="text/css" href="../../css/order.css" />-->
		<link rel="stylesheet" type="text/css" href="../../css/mine.css" />
		<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_9ign9j39fyl.css" />
		<title>申请付款</title>
		<script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
		.mine-content {
			margin-top: 0;
			padding: 0;
		}
	</style>

	<body>
		<div class="mine-content">
			<div class="company-name1">
				<div class="hasticketMoney">
					<p class="p1">已选择开票金额(元)</p>
					<p class="p2">888888888.88</p>
				</div>
				<div class="hadticketMoney">
					<div class="ticketLef">
						<p class="p3">88.88</p>
						<p class="p4">应该开票金额(元)</p>
					</div>
					<div class="ticketRight">
						<p class="p5">88888888.88</p>
						<p class="p6">剩余开票金额(元)</p>
					</div>
				</div>
			</div>
			<div class="tlg">

			</div>
			<ul class="paylist">
				<!--<li>
					<i class="iconfont icon-kongxinweigou"></i>
					<p class="orderNo">合同编号：<span>HYL085456221</span></p>
					<p class="orderMoney">成交金额：<span>888888888.88</span></p>
					<p class="discript">蒸发器，空调，洗衣机，电冰箱,蒸发器，空调，洗衣机，电冰箱</p>
				</li>
				<li>
					<i class="iconfont icon-kongxinweigou"></i>
					<p class="orderNo">合同编号：<span>HYL085456221</span></p>
					<p class="orderMoney">成交金额：<span>888888888.88</span></p>
					<p class="discript">蒸发器，空调，洗衣机，电冰箱,蒸发器，空调，洗衣机，电冰箱</p>
				</li>
				<li>
					<i class="iconfont icon-kongxinweigou"></i>
					<p class="orderNo">合同编号：<span>HYL085456221</span></p>
					<p class="orderMoney">成交金额：<span>888888888.88</span></p>
					<p class="discript">蒸发器，空调，洗衣机，电冰箱,蒸发器，空调，洗衣机，电冰箱</p>
				</li>-->
			</ul>
		</div>
		<div class="allchecked">
			<i class="iconfont icon-kongxinweigou"></i>
			<span> 全选</span>
			<button class="btn">确定 <span class="num"></span></button>
		</div>
	</body>
	<script type="text/javascript">
		//全部金额，已选金额，剩余可选金额
		var allMoney=0
		var checkMoney=0
		var surplusMoney = 0
		//可选择的长度
		var checklength = 0
		$.ajax({
			type: "get",
			url: baseConfig.localHttp2 + "weChatApi/fgclient/getPayList",
			async: false,
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded',
			},
			data: {
				clientId:baseConfig.login()
			},
			success: function(data) {
				console.log(data)
				var $li = "";
				
				for(var i=0;i<data.content.length;i++){
					var descript="";
					$li += "<li data-id="+data.content[i].id+" data-money="+data.content[i].totalPrice+">"
						if(data.content[i].applyStatus==0){
							$li += "<i class='iconfont icon-kongxinweigou'></i>"
							surplusMoney += data.content[i].totalPrice*1
							checklength++
							allMoney += data.content[i].totalPrice*1
						}			
					$li +=	"<p class='orderNo'>合同编号：<span>"+data.content[i].orderNo+"</span></p>"
					$li +=	"<p class='orderMoney'>成交金额：<span>"+data.content[i].totalPrice+"</span></p>"
						for(var j=0;j<data.content[i].matetialList.length;j++){
								descript += data.content[i].matetialList[j]+" "
						}
						$li += "<p class='discript'>"+descript+"</p>"
					
					$li +=	"</li>"	
				}
				$(".paylist").append($li)
				checkone()
				checkall()
				//初始化
				$(".p3").html(allMoney.toFixed(2))
				$(".p5").html(surplusMoney.toFixed(2))
				$(".p2").html(checkMoney.toFixed(2))
			}
		})
		//加法 
		function  Calculation(){
			checkMoney = 0
			for(var i=0;i<$(".paylist li").length;i++){
				if($(".paylist li ").eq(i).find("i").hasClass("icon-shixinduigoudaibiankuang")){
					checkMoney += $(".paylist li ").eq(i).attr("data-money")*1
				}
			}
			surplusMoney = allMoney*1-checkMoney*1
			$(".p5").html(surplusMoney.toFixed(2))
			$(".p2").html(checkMoney.toFixed(2))
		}

		//单选功能
		function checkone(){
		for(var i = 0; i < $(".paylist li").length; i++) {
			$(".paylist li i").eq(i).on("click", function() {
				if($(this).is(".icon-kongxinweigou")) {
					$(this).addClass("icon-shixinduigoudaibiankuang").removeClass("icon-kongxinweigou")
					if($(this).parents().find(".icon-shixinduigoudaibiankuang").length == checklength) {
						Calculation()
						$(".allchecked i").addClass("icon-shixinduigoudaibiankuang").removeClass("icon-kongxinweigou")
					}else{
						Calculation()
					}
					num()
					
				} else {
					$(this).addClass("icon-kongxinweigou").removeClass("icon-shixinduigoudaibiankuang")
					$(".allchecked i").addClass("icon-kongxinweigou").removeClass("icon-shixinduigoudaibiankuang")
					num()
					Calculation()
				}
			})
		}
	}	
		//全选功能
	function checkall(){	
		$(".allchecked i").on("click", function() {
			//全选
			if($(this).is(".icon-kongxinweigou")) {
				$(this).addClass("icon-shixinduigoudaibiankuang").removeClass("icon-kongxinweigou")
				$(".paylist li i").addClass("icon-shixinduigoudaibiankuang").removeClass("icon-kongxinweigou")
				num()
				Calculation()
			} else {
			//全不选	
				$(this).addClass("icon-kongxinweigou").removeClass("icon-shixinduigoudaibiankuang")
				$(".paylist li i").addClass("icon-kongxinweigou").removeClass("icon-shixinduigoudaibiankuang")
				num()
				Calculation()
			}
		})
	}	
		//判断勾选的多少
		function num() {
			if($(".paylist li ").find(".icon-shixinduigoudaibiankuang").length <= 0) {
				$(".num").html("")
			} else {
				$(".num").html("(" + $(".paylist li ").find(".icon-shixinduigoudaibiankuang").length + ")")
			}

		}
		//点击确认
		$(".allchecked .btn").on("click", function() {
			if(!$(".num").html()) {

			} else {
				$.confirm("为了税务审计的方便，请提供与合同等额的发票。请确保发票明细与订单一致，品名和单价与订单相等。为避免税务风险，请您向金三税务系统上传发票之前，将发票拍照传给我司核对。", function() {
					//点击确认后的回调函数
					var id = ""
					for(var i=0;i<$(".paylist li").length;i++){
						if($(".paylist li ").eq(i).find("i").hasClass("icon-shixinduigoudaibiankuang")){
							id += $(".paylist li ").eq(i).attr("data-id")+","
						}
					}
					$.ajax({
						type: "get",
						url: baseConfig.localHttp2 + "weChatApi/fgclient/applyMoney",
						async: false,
						headers: {
							'Content-Type': 'application/x-www-form-urlencoded',
						},
						data: {
							id:id
						},
						success: function(data) {
							if(data.code==100){
								$.toast("提交成功", "success");
							setTimeout(function(){
								window.location.href = "../../index.html"
							},1000)
								
							}
						}
					})	
//					
				}, function() {
					//点击取消后的回调函数
				});
			}
		})
	</script>

</html>